package com.ruoyi.web.controller.activiti;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activiti.domain.MyHoliday;
import com.ruoyi.activiti.service.IMyHolidayService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工作流Controller
 * 
 * @author ldx
 * @date 2020-12-01
 */
@Controller
@RequestMapping("/activiti/holiday")
public class MyHolidayController extends BaseController
{
    private String prefix = "activiti/holiday";

    @Autowired
    private IMyHolidayService myHolidayService;

    @RequiresPermissions("activiti:holiday:view")
    @GetMapping()
    public String holiday()
    {
        return prefix + "/holiday";
    }

    /**
     * 查询工作流列表
     */
    @RequiresPermissions("activiti:holiday:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MyHoliday myHoliday)
    {
        startPage();
        List<MyHoliday> list = myHolidayService.selectMyHolidayList(myHoliday);
        return getDataTable(list);
    }

    /**
     * 导出工作流列表
     */
    @RequiresPermissions("activiti:holiday:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MyHoliday myHoliday)
    {
        List<MyHoliday> list = myHolidayService.selectMyHolidayList(myHoliday);
        ExcelUtil<MyHoliday> util = new ExcelUtil<MyHoliday>(MyHoliday.class);
        return util.exportExcel(list, "holiday");
    }

    /**
     * 新增工作流
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工作流
     */
    @RequiresPermissions("activiti:holiday:add")
    @Log(title = "工作流", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MyHoliday myHoliday)
    {
        return toAjax(myHolidayService.insertMyHoliday(myHoliday));
    }

    /**
     * 修改工作流
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MyHoliday myHoliday = myHolidayService.selectMyHolidayById(id);
        mmap.put("myHoliday", myHoliday);
        return prefix + "/edit";
    }

    /**
     * 修改保存工作流
     */
    @RequiresPermissions("activiti:holiday:edit")
    @Log(title = "工作流", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MyHoliday myHoliday)
    {
        return toAjax(myHolidayService.updateMyHoliday(myHoliday));
    }

    /**
     * 删除工作流
     */
    @RequiresPermissions("activiti:holiday:remove")
    @Log(title = "工作流", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(myHolidayService.deleteMyHolidayByIds(ids));
    }
}
